package com.moco.launcher.fragment;

import io.netty.channel.ChannelHandlerContext;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import android.R.integer;
import android.animation.Animator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.ViewGroup;
import android.view.ViewPropertyAnimator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.android.volley.AuthFailureError;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.Request.Method;
import com.android.volley.toolbox.StringRequest;
import com.moco.launcher.LauncherApplication;
import com.moco.launcher.R;
import com.moco.launcher.activity.MainActivity;
import com.moco.launcher.activity.NewWifiSettingsActivity;
import com.moco.launcher.activity.PopActivity;
import com.moco.launcher.adapter.CycleViewAdapter;
import com.moco.launcher.adapter.CycleViewOnPageChangeListener;
import com.moco.launcher.adapter.DataAdapter;
import com.moco.launcher.adapter.ViewPagerAdapter;
import com.moco.launcher.bean.MOCO_CONSTANTS;
import com.moco.launcher.bean.ViewAndBitmapBean;
import com.moco.launcher.dialog.WaitDialog;
import com.moco.launcher.link.LinkManager;
import com.moco.launcher.listener.CloudListener;
import com.moco.launcher.listener.OnMusicCategorySelectedListener;
import com.moco.launcher.listener.PlayCallback;
import com.moco.launcher.listener.PopWindowCallback;
import com.moco.launcher.listener.PopWindowStateCallback;
import com.moco.launcher.play.AndroidMusicPlayer;
import com.moco.launcher.play.MocoPlayerClient;
import com.moco.launcher.play.MusicItemInfo;
import com.moco.launcher.view.BaseViewAnimator;
import com.moco.launcher.view.CircleImageView;
import com.moco.launcher.view.HoloCircularProgressBar;
import com.moco.launcher.view.NeedleView;
import com.moco.launcher.view.OzDirectionalViewPager;
import com.nineoldandroids.animation.ObjectAnimator;
import com.oazon.common.Assert;
import com.oazon.common.Logger;
import com.oazon.common.util.ImageUtils;
import com.oazon.common.util.LruCacheUtil;
import com.oazon.common.util.RequestManager;
import com.oazon.common.util.StringUtils;
import com.oazon.common.util.TimeUtils;
import com.oazon.common.util.Utils;
import com.oazon.common.util.curcity.ActivityUtil;
import com.oazon.moco.bean.Metadata;
import com.oazon.moco.bean.ProviderAdapt;
import com.oazon.moco.lan.core.http.bean.DeleteBean;
import com.oazon.moco.lan.core.http.bean.FavoriteBean;
import com.oazon.moco.lan.core.http.bean.JsonMessageType;
import com.oazon.moco.lan.util.LanServer;
import com.oazon.moco.lan.util.UrlDecode;
import com.oazon.moco.link.core.LinkEventController;
import com.oazon.moco.link.core.LinkSDK;
import com.oazon.moco.playlist.PlayListManage;
import com.oazon.moco.playlist.bean.AbstractMedia;
import com.oazon.moco.playlist.bean.GetMediaActionResponse;
import com.oazon.moco.playlist.bean.MediaMetadata;
import com.oazon.moco.playlist.bean.PlayListCurrentMode;
import com.oazon.moco.playlist.bean.Property;
import com.oazon.moco.playlist.db.ServiceMsgDao;
import com.oazon.moco.playlist.http.AysncListener;
import com.oazon.moco.playlist.http.ParamsAysncListener;
import com.oazon.moco.playlist.http.RequestMediaManage;
import com.oazon.sonos.bean.GetMetadata;
import com.oazon.sonos.bean.GetMetadataResponse;
import com.oazon.sonos.core.SonosControler;
import com.oazon.sonos.listener.SonosListener;

public class PlayFragment extends BaseFragment {

	private static final String TAG = "PlayFragment";
	private boolean isPopWindowShow = false;
	private OzDirectionalViewPager pager = null;
	private ViewPagerAdapter mViewPagerAdapter = null;
	private HoloCircularProgressBar mHoloCircularProgressBar;
	private static final int FADE_OUT = 1;
	private static final int SHOW_PROGRESS = 2;
	private static final int UPDATE_BUTTON = 3;
	private NeedleView playneedleView = null;
	private TextView musicView = null;
	private PlayCallback mPlayCallback = null;
	private MediaControllerPopWindow mPopWindow = null;
	private RelativeLayout mPlayPauseUi = null;
	private TextView mActionTitle = null;
	private OnMusicCategorySelectedListener mOnMusicCategorySelectedListener = null;
	private View rootView;
	private LauncherApplication mApp;
	private CycleViewAdapter adapter;
	private Activity activity;

	private Boolean isPfVisibleToUser = false;
	private WaitDialog songLoadingProgress;
	public int preventRepeatedlyProgress = 1;

	private TextView upPopTxt;
	private TextView upPopArt;
	private TextView upPopProvider;

	private Bitmap defaultAlbumBitmap;
	private Bitmap defaultPopBitmap;

	private int PLAY_VIEW_SCROLLING = 1;
	private int PLAY_VIEW_SCROLLED = 2;
	private String RESPONSE_VLAUE_IS_FAVORITE = "1";
	private String RESPONSE_VLAUE_IS_NOTFAVORITE = "0";

	public PlayFragment() {

	}

	// private static long lastSlectTime;
	// private static long lastChangeTime;

	public PlayFragment(Activity activity) {
		this.activity = activity;

	}

	@Override
	public void onStart() {
		adapter.notifyDataSetChanged();
		super.onStart();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();

	}

	public void registerDefaultPlay(OnMusicCategorySelectedListener l) {
		mOnMusicCategorySelectedListener = l;
	}

	public void registerPlayCb(PlayCallback cb) {
		this.mPlayCallback = cb;
	}

	public void unregisterPlayCb(PlayCallback cb) {
		this.mPlayCallback = cb;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

	}

	@Override
	public void onAttach(Activity activity) {
		mApp = ((LauncherApplication) activity.getApplication());
		super.onAttach(activity);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		
		rootView = inflater.inflate(R.layout.play_layout, container, false);
		rootView.setDrawingCacheEnabled(true);
		isPfVisibleToUser = true;
		mActionTitle = (TextView) rootView.findViewById(R.id.action_title);
		mActionTitle.setTextColor(0xffee7b1d);

		pager = (OzDirectionalViewPager) rootView.findViewById(R.id.pager);
		pager.setOnKeyListener(new OnKeyListener() {

			@Override
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				if (event.getRepeatCount() == 0
						&& (keyCode == KeyEvent.KEYCODE_HEADSETHOOK
								|| keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || keyCode == KeyEvent.KEYCODE_SPACE)) {
					if (MocoPlayerClient.getInstance().isPlaying()) {
						MocoPlayerClient.getInstance().pause();
						mPlayPauseUi.setVisibility(View.VISIBLE);
					} else {
						MocoPlayerClient.getInstance().start();
						mPlayPauseUi.setVisibility(View.GONE);
					}
					return false;
				} else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP) {
					if (MocoPlayerClient.getInstance().isPlaying()) {
						MocoPlayerClient.getInstance().stop();
					} else {

					}
					return false;
				} else {

				}
				return false;
			}

		});
		mHoloCircularProgressBar = (HoloCircularProgressBar) rootView
				.findViewById(R.id.holoCircularProgressBar);
		mHoloCircularProgressBar.setProgressColor(0xffee7b1d);
		mHoloCircularProgressBar.setProgressBackgroundColor(0x00000000);
		mHoloCircularProgressBar.setWheelSize(3);
		playneedleView = (NeedleView) rootView.findViewById(R.id.play_needle);

		musicView = (TextView) rootView.findViewById(R.id.music_title);

		musicView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				musicView.requestFocus();
			}

		});
		mViewPagerAdapter = new ViewPagerAdapter(activity);
		adapter = new CycleViewAdapter(mViewPagerAdapter);
		pager.setAdapter(adapter);
		pager.setCurrentItem(1, false);
		PlayListManage.getInstance().registViewPagerAdapter(mViewPagerAdapter);
		mViewPagerAdapter.registerPopWindowCallback(new PopWindowCallback() {
			@Override
			public void show() {
				Logger.d(TAG, "SHOW popwindow");
				if (mPopWindow != null) {
					mPopWindow.show();
					isPopWindowShow = true;
				}
			}

			@Override
			public void hide() {
				if (mPopWindow != null)

					mPopWindow.hide();
				isPopWindowShow = false;
			}

			@Override
			public void showMask() {
			}
		});

		pager.setOnPageChangeListener(new CycleViewOnPageChangeListener(
				new OnPageChangeListener() {

					@Override
					public void onPageScrollStateChanged(int arg0) {
						// michael change: scroll logical error, move the
						// up&down check to onPageSelected

						if (arg0 == PLAY_VIEW_SCROLLING) {
							pauseUI();
						} else if (arg0 == PLAY_VIEW_SCROLLED) {
							playUI();

						}

					}

					@Override
					public void onPageScrolled(int arg0, float arg1, int arg2) {

					}

					@Override
					public void onPageSelected(int arg0) {
						Logger.d(TAG, "======onPageSelected:" + arg0);

						if (arg0 == 2) {// up
							playNext();
						} else if (arg0 == 0) {// down
							playPre();
						} else {
							return;
						}
						updateProgress();

					}
				}, mViewPagerAdapter, pager));

		mPopWindow = new MediaControllerPopWindow(activity);
		mPopWindow.setAnchorView(rootView);
		mPopWindow.setMediaPlayer(MocoPlayerClient.getInstance());
		mPopWindow.setStateCallback(new PopWindowStateCallback() {

			@Override
			public void pause() {
				showPauseState();
			}

			@Override
			public void play() {
				showPlayState();
			}

			@Override
			public void favorite(boolean isFavorite) {
				loveCurrentMetadata(isFavorite, null);

			}

			@Override
			public void delete() {
				deleteCurrentMetadata(true);
			}

			@Override
			public void reRequestSmartRadio() {
				requestSmartRadio();

			}

			@Override
			public void playItem(int i) {
				PlayFragment.this.playItem(i);

			}
		});

		if (mOnMusicCategorySelectedListener != null
				&& PlayListManage.getInstance().size() == 0)
			mOnMusicCategorySelectedListener.onMusicRecommand();
		// 解决开机语音识别崩溃的问题
		Logger.i(TAG,
				"wifi connect==" + !Utils.isWifiConnectedOrConnecting(activity));
		if (!Utils.isWifiConnectedOrConnecting(activity)) {
			Intent intentwifi = new Intent(activity,
					NewWifiSettingsActivity.class);
			startActivityForResult(intentwifi, 12);
		}
		
		LauncherApplication.getInstance().registerPlayFragment(this);
		return rootView;
	}

	public void deleteCurrentMetadata(boolean isDelete) {

		Metadata curMetadata = PlayListManage.getInstance().getCurrentMedia();
		if (curMetadata == null) {
			return;
		}
		String provider = curMetadata.getServiceID();
		String itemId = curMetadata.getItemID();

		DeleteBean bean = new DeleteBean();
		bean.setDelete(isDelete);
		if (itemId == null) {
			Logger.e(TAG, "当前的歌曲id是空的");
			return;
		}
		bean.setCurrentItemID(itemId);

		if (Utils.isO2(provider)) {
			provider = "";
		}// 2015.6.23 v.c
		else if (isDelete == true) {
			curMetadata.setAudioUrl(AndroidMusicPlayer.getInstance()
					.getMp3Path());
			Logger.i(TAG, "cur==" + JSON.toJSONString(curMetadata));
			postO2LoveOrDeleteSongByOther(MOCO_CONSTANTS.POST_TO_O2_SONGSLIST,
					provider, JSON.toJSONString(curMetadata), null, "removed");
		}

		bean.setProvider(provider);
		deleteMetadata(bean, null);
		deleteCurrentSongHandler.sendEmptyMessage(1);
	}

	Handler deleteCurrentSongHandler = new Handler() {
		public void handleMessage(Message msg) {
			deleteCurrentSong();
		};
	};

	public void deleteCurrentSong() {
		// 在当前播放列表中删除,并切换到下一首歌

		if (activity instanceof MainActivity) {
			((MainActivity) activity).exitPauseUI();
		}

		int index = PlayListManage.getInstance().getCurrentIndex();
		PlayListManage.getInstance().remove(index);
		if (index <= PlayListManage.getInstance().size()) {
			// 如果是在队列模式，则转成电台模式，如果是电台模式则再请求歌曲
			if (PlayListManage.getInstance().getSaveCurrentMode() == PlayListCurrentMode.QUEUE) {
				PlayListManage.getInstance().toSmartRadio(null);
			} else {
				requestSmartRadio();
			}
		}

		index = PlayListManage.getInstance().getCurrentIndex();
		playItem(index);
		mPopWindow.updateFavorite();
	}

	public void deleteMetadata(DeleteBean deleteBean,
			final ChannelHandlerContext ctx) {
		String url = "http://";
		try {
			Map<String, String> params = new HashMap<String, String>();

			UrlDecode.parseParameters(params, MOCO_CONSTANTS.DELETE_URI, null);
			params.put("mediaId", deleteBean.getCurrentItemID());
			params.put("delete", String.valueOf(deleteBean.isDelete()));
			params.put("provider", deleteBean.getProvider());
			url = UrlDecode.getUrl(params, MOCO_CONSTANTS.DELETE_URI, null);
			url = url.replace(" ", "");
			Logger.e(TAG, "Delete_url==" + url);
			Logger.v(TAG, "Delete_url==" + url);
		} catch (Exception e) {
			Logger.v(TAG, "网络请求删除歌曲之前崩溃");
			LanServer.responseResult(JsonMessageType.DELETE.toString(), -1,
					null, ctx);
		}

		RequestManager.sendpost(activity, url, new CloudListener() {

			@Override
			public void onResponse(String response) {
				Logger.i(TAG, "Love_response==" + response);
				if (response == null
						|| PlayListManage.getInstance().getCurrentMedia() == null) {
					onError(0, "null");
					return;
				}
				Toast.makeText(PlayFragment.this.getContext(), "好的，我会少放这类歌曲",
						Toast.LENGTH_SHORT).show();

				mPopWindow.setFavorite(false);
				if (PlayListManage.getInstance().getCurrentMedia() != null) {
					PlayListManage.getInstance().getCurrentMedia()
							.setFavorite(false);
				}

				// 删除收藏的歌曲，假如这首歌之前是收藏的，现在要删除
				GetMetadataResponse<AbstractMedia> result = RequestManager
						.parseJsonResponse(response);
				if (result == null
						|| result.getGetMetadataResult()
								.getMediaCollectionOrMediaMetadata().size() <= 0)
					return;

				/*
				 * michael remove: useless code MediaMetadata mediaMetadata =
				 * (MediaMetadata) result .getGetMetadataResult()
				 * .getMediaCollectionOrMediaMetadata().get(0);
				 * 
				 * Metadata bean = DataAdapter.dateAdapator(mediaMetadata, null,
				 * "o2");
				 */
				LanServer.responseResult(JsonMessageType.DELETE.toString(), 0,
						null, ctx);
				// MocoDownloadManager.getInstance().removeDownload(info);
			}

			@Override
			public void onError(int err, String msg) {
				/*
				 * Toast.makeText(PlayFragment.this.getContext(), "删除失败",
				 * Toast.LENGTH_SHORT).show();
				 */
				LanServer.responseResult(JsonMessageType.DELETE.toString(), -1,
						null, ctx);
			}
		});

	}

	public void loveCurrentMetadata(final boolean isFavorite,
			final ChannelHandlerContext ctx) {

		Metadata curMetadata = PlayListManage.getInstance().getCurrentMedia();
		if (curMetadata == null) {
			return;
		}
		String provider = curMetadata.getServiceID();
		String itemId = curMetadata.getItemID();

		FavoriteBean bean = new FavoriteBean();
		bean.setLike(isFavorite);
		if (itemId == null) {
			Logger.e(TAG, "当前的歌曲id是空的");
			return;
		}
		bean.setCurrentItemID(itemId);
		Logger.i(TAG, "provider==" + provider);
		Logger.i(TAG, "isFavorite==" + isFavorite);
		if (Utils.isO2(provider)) {
			provider = "";
		}// 2015.6.23 v.c
		else if (isFavorite == true) {

			curMetadata.setAudioUrl(AndroidMusicPlayer.getInstance()
					.getMp3Path());

			Logger.i(TAG, "cur==" + JSON.toJSONString(curMetadata));//
			postO2LoveOrDeleteSongByOther(MOCO_CONSTANTS.POST_TO_O2_SONGSLIST,
					provider, JSON.toJSONString(curMetadata), ctx, "favorite");
			return;
		}
		bean.setProvider(provider);
		loveMetadata(bean, ctx);
	}

	public void loveMetadata(final FavoriteBean favoriteBbean,
			final ChannelHandlerContext ctx) {
		String url = "http://";
		try {
			Map<String, String> params = new HashMap<String, String>();

			UrlDecode.parseParameters(params, MOCO_CONSTANTS.LOVE_URI, null);
			params.put("mediaId", favoriteBbean.getCurrentItemID());
			params.put("isFavorite", String.valueOf(favoriteBbean.isLike()));
			params.put("provider", favoriteBbean.getProvider());
			url = UrlDecode.getUrl(params, MOCO_CONSTANTS.LOVE_URI, null);
			url = url.replace(" ", "");
			Logger.e(TAG, "Love_url==" + url);
		} catch (Exception e) {
			Logger.v(TAG, "网络请求收藏歌曲之前崩溃");
			LanServer.responseResult(JsonMessageType.FAVORITE.toString(), -1,
					null, ctx);
		}

		RequestManager.sendpost(activity, url, new CloudListener() {

			@Override
			public void onResponse(String response) {

				Logger.i(TAG, "Love_response==" + response);
				if (response == null) {
					onError(0, "null");
					return;
				}
				if (ctx == null) {
					LinkManager.getInstance().favorite(favoriteBbean);
				}
				/*
				 * michael remove: useless code MediaMetadata mediaMetadata =
				 * (MediaMetadata) result .getGetMetadataResult()
				 * .getMediaCollectionOrMediaMetadata().get(0);
				 * 
				 * Metadata bean = DataAdapter.dateAdapator(mediaMetadata, null,
				 * "o2");
				 */
				// 当resopnse返回“{"message":"系统错误，操作失败","status":"ERROR"}”时，调用catch
				try {
					GetMetadataResponse<AbstractMedia> result = RequestManager
							.parseJsonResponse(response);
					MediaMetadata mediaMetadata = (MediaMetadata) result
							.getGetMetadataResult()
							.getMediaCollectionOrMediaMetadata().get(0);
					String isLikeResult = mediaMetadata.getDynamic()
							.getProperty().get(0).getValue();
					if (isLikeResult.equals(RESPONSE_VLAUE_IS_FAVORITE)) {

						Toast.makeText(PlayFragment.this.getContext(), "收藏成功",
								Toast.LENGTH_SHORT).show();
						mPopWindow.setFavorite(true);
						PlayListManage.getInstance().getCurrentMedia()
								.setFavorite(true);
						/*
						 * FavoriteBean favoriteBean = new FavoriteBean();
						 * favoriteBean.setProvider(songprovider);
						 * favoriteBean.setLike(true);
						 */
						// MocoDownloadManager.getInstance().startDownload(info);
					} else if ((isLikeResult
							.equals(RESPONSE_VLAUE_IS_NOTFAVORITE))) {
						Toast.makeText(PlayFragment.this.getContext(),
								"取消收藏成功", Toast.LENGTH_SHORT).show();
						mPopWindow.setFavorite(false);
						PlayListManage.getInstance().getCurrentMedia()
								.setFavorite(false);
						// MocoDownloadManager.getInstance().removeDownload(info);
						if (ctx == null) {
							LinkManager.getInstance().favorite(favoriteBbean);
						}
					}
				} catch (Exception e) {
					// TODO: handle exception
					Logger.e(TAG, "Exception==" + e.getMessage());
					Logger.e(TAG, "解析失败");
					onError(0, "loveMetadata_response_Error");
				}

				LanServer.responseResult(JsonMessageType.FAVORITE.toString(),
						0, null, ctx);
			}

			@Override
			public void onError(int err, String msg) {
				Logger.e(TAG, "Love_response_error==" + msg);
				if (favoriteBbean.isLike()) {
					Toast.makeText(PlayFragment.this.getContext(), "收藏失败",
							Toast.LENGTH_SHORT).show();
					mPopWindow.setFavorite(false);
				} else {
					Toast.makeText(PlayFragment.this.getContext(), "取消收藏失败",
							Toast.LENGTH_SHORT).show();
					mPopWindow.setFavorite(true);
				}
				LanServer.responseResult(JsonMessageType.FAVORITE.toString(),
						-1, null, ctx);
			}
		});

	}

	public void requestSmartRadio() {

		PlayListManage playListManage = PlayListManage.getInstance();
		Logger.d(TAG, "requestSmartRadio====" + playListManage.size()
				+ "===readIndex==" + playListManage.getReadIndex());
		GetMetadata getMetadata = playListManage.getGetMetadata();
		if (getMetadata != null
				&& playListManage.getSaveCurrentMode() == PlayListCurrentMode.SMART_RADIO
				&& (playListManage.getReadIndex() >= playListManage.size() - 2 || playListManage
						.size() < 5)) {

			Logger.d(TAG,
					"requestSmartRadio====request----" + playListManage.size());
			ServiceMsgDao dao = ServiceMsgDao.getInstance(activity);
			SonosControler.getInstance(this.getContext(),
					dao.getServiceMsgByProvider(getMetadata.getProvider()))
					.getMetadata(this.getContext(), getMetadata,
							new SonosListener() {

								@Override
								public void onResponse(Object response) {

									if (response == null)
										return;
									if (response instanceof GetMetadataResponse) {
										@SuppressWarnings("unchecked")
										GetMetadataResponse<AbstractMedia> result = (GetMetadataResponse<AbstractMedia>) response;
										Metadata temp = PlayListManage
												.getInstance().getMedia(0);
										if (temp == null) {
											temp = new Metadata();
										}

										List<Metadata> metadatas = DataAdapter
												.paseMetadatas(
														result.getGetMetadataResult()
																.getMediaCollectionOrMediaMetadata(),
														temp.getParentID(),
														temp.getServiceID());

										PlayListManage.getInstance().addAll(
												metadatas);
									}

								}

								@Override
								public void onError(int err, String msg) {

								}
							});
		}
	}

	@Override
	public void onDestroyView() {
		mPopWindow.onDestroy();
		super.onDestroyView();
	}

	public void showPauseStateUI() {
		if (!isPopWindowShow) {
			if (MocoPlayerClient.getInstance().isPlaying()) {
				MocoPlayerClient.getInstance().pause();
				mPlayPauseUi.setVisibility(View.VISIBLE);
			} else {
				MocoPlayerClient.getInstance().start();
				mPlayPauseUi.setVisibility(View.GONE);
			}
		}
	}

	public void showPlayState() {
		playUI();
		MocoPlayerClient.getInstance().start();
		Intent intent = new Intent(activity, PopActivity.class);
		intent.putExtra("fragment_type", "finish");
		activity.startActivity(intent);
	}

	public void playUI() {
		playNeedlerDown();
		startRoll();
	}

	public void showPauseState() {
		pauseUI();
		mApp.setTempObject("pause", rootView.getDrawingCache());
		Intent intent = new Intent(activity, PopActivity.class);
		intent.putExtra("fragment_type", "pause");
		activity.startActivity(intent);

	}

	public void pauseUI() {
		Logger.d(TAG, "pauseUI");
		stopRoll();
		playNeedlerUp();
	}

	public void showStopStateUI() {
		if (!isPopWindowShow) {
			if (MocoPlayerClient.getInstance().isPlaying()) {
				stopRoll();
				playNeedlerUp();
				MocoPlayerClient.getInstance().stop();
			}
		}
	}

	public void playNeedlerUp() {

		float pivotX = playneedleView.getPaddingLeft()
				+ playneedleView.getWidth() * 5 / 8;
		float pivotY = playneedleView.getPaddingTop();
		playneedleView.setPivotX(pivotX);
		playneedleView.setPivotY(pivotY);
		ViewPropertyAnimator property = playneedleView.animate();
		property.rotation(-30);
		property.setDuration(500);
		property.setListener(new Animator.AnimatorListener() {

			@Override
			public void onAnimationStart(Animator animation) {

			}

			@Override
			public void onAnimationEnd(Animator animation) {
				playneedleView.setImageResource(R.drawable.pause_needle);
			}

			@Override
			public void onAnimationCancel(Animator animation) {
				playneedleView.setImageResource(R.drawable.play_needle);
			}

			@Override
			public void onAnimationRepeat(Animator animation) {

			}
		});
		property.start();
	}

	public void playNeedlerDown() {
		float pivotX = playneedleView.getPaddingLeft()
				+ playneedleView.getWidth() * 5 / 8;
		float pivotY = playneedleView.getPaddingTop();
		playneedleView.setPivotX(pivotX);
		playneedleView.setPivotY(pivotY);
		ViewPropertyAnimator property = playneedleView.animate();
		property.rotation(0);
		property.setDuration(500);
		property.setListener(new Animator.AnimatorListener() {

			@Override
			public void onAnimationStart(Animator animation) {
				Logger.d(TAG, "onAnimationStart");
				playneedleView.setImageResource(R.drawable.play_needle);
			}

			@Override
			public void onAnimationEnd(Animator animation) {

			}

			@Override
			public void onAnimationCancel(Animator animation) {

			}

			@Override
			public void onAnimationRepeat(Animator animation) {

			}
		});
		property.start();

	}

	@Override
	public void onResume() {
		super.onResume();
	}

	@SuppressLint("HandlerLeak")
	private Handler mHandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			long pos;
			switch (msg.what) {
			case UPDATE_BUTTON:
				// updateButtonStatus();
				break;
			case FADE_OUT:
				if (mHoloCircularProgressBar != null) {
					mHoloCircularProgressBar.setVisibility(View.INVISIBLE);
					mHoloCircularProgressBar.setProgress(0);
				}
				break;
			case SHOW_PROGRESS:
				mHoloCircularProgressBar.setVisibility(View.VISIBLE);
				pos = setProgress();
				msg = obtainMessage(SHOW_PROGRESS);
				sendMessageDelayed(msg, 360 - (pos % 360));
				break;
			}
		}
	};

	private long setProgress() {
		if (!MocoPlayerClient.getInstance().isPlaying())
			return 0;

		long position = MocoPlayerClient.getInstance().getCurrentPosition();
		long duration = MocoPlayerClient.getInstance().getDuration();
		// Log.d(TAG, "position= " + position + "duration= " + duration);

		if (position == -1) {
			position = 0;
		}
		if (duration > 0) {
			long pos = position * 360 / duration;
			float per = pos % 360;
			mHoloCircularProgressBar.setProgress(per);
		}
		LinkManager.getInstance().saveProgress(position);
		return position;
	}

	public void playItem(int i) {
		PlayListManage.getInstance().pauseAutoLoad();
		playItemHandler.removeMessages(0x31);
		if (isPfVisibleToUser == true) {
			loadingHandler.sendEmptyMessage(0x11);
		}
		Message message = playItemHandler.obtainMessage();
		message.arg1 = i;
		message.what = 0x31;
		playItemHandler.sendMessageDelayed(message, 300);
		preventRepeatedlyProgress = 1;
	}

	public void setProgressCount() {
		preventRepeatedlyProgress = 2;
	}

	private Handler playItemHandler = new Handler() {
		public void handleMessage(Message msg) {
			showMediaInfo(msg.arg1);
		};
	};

	/*
	 * public void songLoadingDismiss() { if (songLoadingProgress != null &&
	 * songLoadingProgress.isShowing()) { songLoadingProgress.dismiss(); } }
	 */

	Handler loadingHandler = new Handler() {
		public void handleMessage(Message msg) {

			if (preventRepeatedlyProgress == 2) {
				setsongLoadProgressDis();
			}
			if (songLoadingProgress != null) {
				if (!songLoadingProgress.isShowing()) {
					songLoadingProgress.show();
				} else {

				}
			} else {
				songLoadingProgress = WaitDialog.createDialog(activity);
				songLoadingProgress.show();
			}
			PlayListManage playListManage = PlayListManage.getInstance();
			if (playListManage.size() == 0) {

				setsongLoadProgressDis();
			}
			if (isPfVisibleToUser == false) {
				setsongLoadProgressDis();

			}
		};
	};

	public void setsongLoadProgressDis() {
		if (songLoadingProgress != null && songLoadingProgress.isShowing()) {
			songLoadingProgress.dismiss();
		}
	}

	private void showMediaInfo(int i) {
		Log.d("wwww", "showMediaInfo===" + i);
		FrameLayout upPop;
		ImageView upPopImage;
		MusicItemInfo info = DataAdapter.dateAdapator(PlayListManage
				.getInstance().getPlay(i));
		if (info == null) {
			return;
		}
		// i = PlayListManage.getInstance().getIndex(info.getId());
		mPlayCallback.playItem(info);

		progressUpdateStop();
		if (mViewPagerAdapter == null) {
			return;
		}
		View view = mViewPagerAdapter.getCurrentView();
		if (view == null) {
			return;
		}

		upPop = (FrameLayout) ((ViewGroup) view).getChildAt(2);
		upPopImage = (ImageView) upPop.getChildAt(0);
		LinearLayout linLay = (LinearLayout) upPop.getChildAt(1);
		if (linLay != null) {
			upPopTxt = (TextView) linLay.getChildAt(0);
			upPopArt = (TextView) linLay.getChildAt(1);
			upPopProvider = (TextView) linLay.getChildAt(1);
		}

		fillImage(PlayListManage.getInstance().getReadIndex(), view, upPopImage);

		showTitle();// michael: move to the logical to a function

		updateProgress();
		playUI();

		if (songLoadingProgress != null)
			songLoadingProgress.dismiss();

	}

	private void showTitle() {
		Metadata metadata = PlayListManage.getInstance().getCurrentMedia();
		if (metadata != null) {
			if (upPopArt != null) {
				if (StringUtils.isBlank(metadata.getArtist())) {
					upPopArt.setText("未知");
				} else {
					upPopArt.setText(metadata.getArtist());
				}
			}

			if (upPopTxt != null) {
				if (!StringUtils.isEmpty(metadata.getTitle())) {
					upPopTxt.setText(metadata.getTitle());
				}
			}
			if (upPopProvider != null) {
				if (!StringUtils.isEmpty(metadata.getServiceID())) {
					if (!("".equals(metadata.getServiceID()) || //
							"moco".equals(metadata.getServiceID()) || //
					"o2".equals(metadata.getServiceID()))) {
						upPopProvider.setText("来自:"
								+ ProviderAdapt.provider2name(metadata
										.getServiceID()));
					}
				}
			}
			Logger.i(TAG, "paly_loved==" + metadata.isFavorite());
		}
	}

	private void fillImage(int i, View view, final ImageView upPopImage) {
		if (view == null) {
			return;
		}
		if (i < 0) {
			i = PlayListManage.getInstance().size() - 1;
		} else if (i >= PlayListManage.getInstance().size()) {
			i = 0;
		}

		if (defaultAlbumBitmap == null) {
			defaultAlbumBitmap = BitmapFactory.decodeResource(getResources(),
					R.drawable.album_default);
		}
		if (defaultPopBitmap == null) {
			defaultPopBitmap = BitmapFactory.decodeResource(getResources(),
					R.drawable.up_pop);
		}
		ViewGroup group = (ViewGroup) view;
		final CircleImageView circleImageView = (CircleImageView) group
				.getChildAt(1);
		try {
			Logger.d(TAG, "requestBitmap  "
					+ PlayListManage.getInstance().getMedia(i));
			if (PlayListManage.getInstance().getMedia(i) == null
					|| PlayListManage.getInstance().getMedia(i)
							.getAlbumArtURI() == null) {
				return;
			}

			Logger.d("PlayListManage", "fillImage index === "+i);
			final String url = PlayListManage.getInstance().getMedia(i)
					.getAlbumArtURI();

			Map<String, Object> params = new HashMap<String, Object>();
			params.put("url", url);
			PlayListManage.getInstance().pauseAutoLoad();

			fillDefaultImg(upPopImage, circleImageView);

			RequestMediaManage.getInstance(activity).requestBitmap(url,
					new ParamsAysncListener(params) {

						@Override
						public void onSuccess(Object arg0) {
							PlayListManage.getInstance().reStartAutoLoad();
							try {
								Logger.i(
										"requestImage",
										"request__onSuccess==bg"
												+ TimeUtils.getCurrentTimeSec()
												+ "\r\n  url === " + url);
								if (arg0 == null) {
									fillDefaultImg(upPopImage, circleImageView);
									return;
								}

								Message msg = fillImageHandler.obtainMessage();
								List<ViewAndBitmapBean> beans = new ArrayList<ViewAndBitmapBean>();

								Bitmap upPopBitmap = LruCacheUtil.getInstance()
										.getBitmapFromMemCache(url + "blur");
								if (upPopBitmap == null) {
									upPopBitmap = getBlurBitmap(arg0,
											String.valueOf(params.get("url")));
									LruCacheUtil.getInstance()
											.addBitmapToMemoryCache(
													url + "blur", upPopBitmap);
								}

								beans.add(new ViewAndBitmapBean(
										circleImageView, (Bitmap) arg0));

								beans.add(new ViewAndBitmapBean(upPopImage,
										upPopBitmap));
								msg.obj = beans;
								msg.what = 0x01;
								Logger.i("requestImage",
										"request__fillImageHandler==bg"
												+ TimeUtils.getCurrentTimeSec()
												+ "\r\n  url === " + url);
								fillImageHandler.sendMessage(msg);
							} catch (Exception e) {
								Logger.e(TAG,
										"getImage to blur==" + e.getMessage());
							}
						}

						@Override
						public void onError(String arg0) {
							PlayListManage.getInstance().reStartAutoLoad();
							Logger.d("wowdd2", "onError");
							fillDefaultImg(upPopImage, circleImageView);
						}

						private Bitmap getBlurBitmap(Object arg0, String url) {
							Bitmap upPopBitmap = ImageUtils.toRoundBitmap(
									PlayFragment.this.getContext(),
									ImageUtils.blur((Bitmap) arg0, 6));
							return upPopBitmap;
						}

					});
		} catch (NullPointerException e) {
			circleImageView.setImageResource(R.drawable.album_default);
			if (upPopImage != null) {
				upPopImage.setImageResource(R.drawable.up_pop);
			}

		}

	}

	private void fillDefaultImg(final ImageView upPopImage,
			final CircleImageView circleImageView) {
		Message msg = fillImageHandler.obtainMessage();
		List<ViewAndBitmapBean> beans = new ArrayList<ViewAndBitmapBean>();
		beans.add(new ViewAndBitmapBean(upPopImage, defaultPopBitmap));
		beans.add(new ViewAndBitmapBean(circleImageView, defaultAlbumBitmap));

		msg.obj = beans;
		msg.what = 0x01;
		fillImageHandler.sendMessage(msg);
	}

	private Handler fillImageHandler = new Handler() {
		public void handleMessage(Message msg) {
			if (msg.what == 0x01) {
				List<ViewAndBitmapBean> viewAndBitmap = (List<ViewAndBitmapBean>) msg.obj;
				for (ViewAndBitmapBean viewAndBitmapBean : viewAndBitmap) {
					ImageView imageView = viewAndBitmapBean.getView();
					Bitmap bitmap = viewAndBitmapBean.getBitmap();
					if (imageView != null && bitmap != null) {
						imageView.setImageBitmap(bitmap);
					}
				}
				viewAndBitmap.clear();
			}
		};
	};

	public void hideTitle() {
		if (upPopArt == null || upPopTxt == null) {
			return;
		}
		upPopTxt.setText("");
		upPopArt.setText("");
	}

	class Status {
		boolean bStart = false;
	}

	boolean bStart = false;

	public void CircleStartRotation() {
		try {
			View view = mViewPagerAdapter.getCurrentView();
			if (view == null)
				return;
			Logger.d(TAG, "CircleStartRotation==" + view.toString());

			startAlbumAnimation(view);
		} catch (Exception e) {
		}
	}

	public void CircleStopRotation() {

		View view = mViewPagerAdapter.getCurrentView();
		if (view != null) {
			stopAlbumAnimation(view);
		}
	}

	public void updateProgress() {
		activity.runOnUiThread(new Runnable() {

			@Override
			public void run() {
				mHoloCircularProgressBar.setProgress(0);
				mHandler.sendEmptyMessage(SHOW_PROGRESS);

			}
		});
	}

	public void progressUpdateStop() {
		mHandler.sendEmptyMessage(FADE_OUT);
	}

	public void resetCurrentItem(String id) {
		// int i = mViewPagerAdapter.getIndex(id);
		// mViewPagerAdapter.setCurrentItem(i, false);
	}

	public void switchIndex(String id) {
		Logger.d(TAG, "starty switch to ");
		int i = PlayListManage.getInstance().getIndex(id);
		if (i == -1) {
			return;
		}
		playItem(i);
		startRoll();
		playNeedlerDown();
		Logger.d(TAG, "switch to " + i);
	}

	public void startRoll() {
		CircleStartRotation();
		updateProgress();
	}

	public void stopRoll() {
		CircleStopRotation();
		progressUpdateStop();
	}

	/*
	 * public void setData(ArrayList<MusicItemInfo> playList) { if
	 * (playList.size() == 0) { this.stopRoll(); }
	 * mViewPagerAdapter.setCurrentItem(1, false);
	 * mViewPagerAdapter.setData(playList);
	 * mViewPagerAdapter.notifyDataSetChanged(true); }
	 */

	public class RotationOutAnimator extends BaseViewAnimator {

		@Override
		public void prepare(View target) {
			getAnimatorAgent().playTogether(
					ObjectAnimator.ofFloat(target, "alpha", 1, 0));
		}
	}

	public class RotationInAnimator extends BaseViewAnimator {

		int m_orientation = -1;

		public void setOrientation(int orientation) {
			m_orientation = orientation;
		}

		@Override
		public void prepare(View target) {
			float x = target.getPivotX() + 250;
			float y = target.getHeight() - target.getPaddingTop();
			getAnimatorAgent().playTogether(
					ObjectAnimator.ofFloat(target, "rotation", -30, 0),
					ObjectAnimator.ofFloat(target, "pivotX", x, x),
					ObjectAnimator.ofFloat(target, "pivotY", y, y));
		}
	}

	public void startAlbumAnimation(final View view) {
		Logger.d("PlayListManage", "startAlbumAnimation===" + view.toString());

		view.clearAnimation();
		RotateAnimation rotateAnimation = new RotateAnimation(0, 359,
				Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
				0.5f);
		rotateAnimation.setDuration(25000);
		rotateAnimation.setInterpolator(new LinearInterpolator());
		rotateAnimation.setRepeatCount(-1);
		rotateAnimation.setStartOffset(700);
		rotateAnimation.setRepeatMode(Animation.RESTART);
		rotateAnimation.setFillAfter(true);
		rotateAnimation.setFillEnabled(true);

		AnimationSet animationSet = new AnimationSet(true);

		AlphaAnimation alphaAnimation = (AlphaAnimation) AnimationUtils
				.loadAnimation(getContext(), R.anim.up_pop_out);

		alphaAnimation.setFillAfter(true);

		animationSet.addAnimation(alphaAnimation);
		animationSet.setFillAfter(true);
		animationSet.setStartOffset(2000);

		if (view != null) {
			view.startAnimation(rotateAnimation);
			FrameLayout frameLayout = (FrameLayout) ((ViewGroup) view)
					.getChildAt(2);
			frameLayout.clearAnimation();
			frameLayout.startAnimation(animationSet);
		}
	}

	public void stopAlbumAnimation(View view) {
		if (view != null) {
			Logger.d(TAG, "stopAlbumAnimation");
			FrameLayout frameLayout = (FrameLayout) ((ViewGroup) view)
					.getChildAt(2);
			view.clearAnimation();
			frameLayout.clearAnimation();
		}
	}

	public long getCurMediaDuration() {
		return MocoPlayerClient.getInstance().getDuration();
	}

	public void setCurrentItem(final int i) {
		playItem(i);
	}

	public void addSmartRadioAndPlay(List<Metadata> metadatas,
			GetMetadata getMetadata) {
		PlayListManage.getInstance().toSmartRadio(getMetadata);
		PlayListManage.getInstance().addAll(metadatas);
		if(PlayListManage.getInstance().size() ==0){
			playItem(0);
		}else{
			playItem(PlayListManage.getInstance().getReadIndex() + 1);		
		}
	}

	public void addQueueAndPlay(List<Metadata> metadatas) {
		PlayListManage.getInstance().toQueue();
		PlayListManage.getInstance().addAll(metadatas);
		playItem(PlayListManage.getInstance().getReadIndex());
	}

	public void addPlayItem(int index, Metadata metadata) {
		PlayListManage.getInstance().add(metadata, index);
		playItem(PlayListManage.getInstance().getReadIndex()+1);
	}

	public boolean addPlayList(int index, List<Metadata> metadatas) {
		return PlayListManage.getInstance().addAll(metadatas, index);
		// showTitle(index);
	}

	public void addPlayList(List<Metadata> metadatas) {
		PlayListManage.getInstance().addAll(metadatas);
	}

	public void setCurrentItem() {
		playItem(PlayListManage.getInstance().getReadIndex());
	}

	public void resetAdapter() {
		pager.reSetAdapter(1);
	}

	public void playNext() {
		int index;

		Intent intent = new Intent(activity, PopActivity.class);
		intent.putExtra("fragment_type", "finish");
		activity.startActivity(intent);

		setRepeatSharedPreferences();
		mPopWindow.mSingleLoopView.setImageResource(mPopWindow.mContext
				.getResources().getIdentifier("loop_dark", "drawable",
						mContext.getPackageName()));
		mPopWindow.mPlayer.setLoopMode(mPopWindow.LOOP_NO_SINGLE);

		index = PlayListManage.getInstance().getReadIndex() + 1;
        Log.e("test ples del", "index"+index);
		if (index >= PlayListManage.getInstance().size()) {
			index = 0;
		}

		if (mPopWindow != null) {
			if (PlayListManage.getInstance().isFavorite(index)) {
				mPopWindow.setFavorite(true);
			} else {
				mPopWindow.setFavorite(false);
			}
		}

		playItem(index);
	}

	public void playPre() {
		Intent intent = new Intent(activity, PopActivity.class);
		intent.putExtra("fragment_type", "finish");
		activity.startActivity(intent);
		Logger.d("WGZ", "playPrev");
		setRepeatSharedPreferences();
		mPopWindow.mSingleLoopView.setImageResource(mPopWindow.mContext
				.getResources().getIdentifier("loop_dark", "drawable",
						mContext.getPackageName()));
		mPopWindow.mPlayer.setLoopMode(mPopWindow.LOOP_NO_SINGLE);
		int index;
		// 向下滑播放上一首
		index = PlayListManage.getInstance().getReadIndex() - 1;
		if (index < 0) {
			index = PlayListManage.getInstance().size() - 1;
		}
		/* if(isFastSlectClick()){ */
		playItem(index);
		/* } */

	}

	@Override
	public void setUserVisibleHint(boolean isVisibleToUser) {
		// TODO Auto-generated method stub
		if (isVisibleToUser) {
			isPfVisibleToUser = true;
		} else {
			isPfVisibleToUser = false;

		}
		super.setUserVisibleHint(isVisibleToUser);
	}

	public void setRepeatSharedPreferences() {
		SharedPreferences mSharedPreferences = activity.getSharedPreferences(
				Utils.CONFIG_FILE, MainActivity.MODE_PRIVATE);
		Logger.d(
				TAG,
				"main_single=="
						+ mSharedPreferences.getBoolean("single_loop", false));
		if (mSharedPreferences.getBoolean("single_loop", false)) {
			Editor editor = mSharedPreferences.edit();
			editor.putBoolean("single_loop", false);
			editor.commit();
		}
	}

	/*
	 * public static boolean isFastSlectClick() { long time =
	 * System.currentTimeMillis(); long timeD = time - lastSlectTime; if ( 0 <
	 * timeD && timeD < 500) { Log.e("", true+"slect"); return true;
	 * 
	 * }else{ Log.e("", false+"slect"); } Log.e("", time+"time:"); Log.e("",
	 * lastSlectTime+"lastClickTime"); lastSlectTime = time; return false;
	 * 
	 * } public static boolean isFastChangeClick() { long time =
	 * System.currentTimeMillis(); long timeD = time - lastChangeTime; if ( 0 <
	 * timeD && timeD < 500) { Log.e("", true+"change:"); return true;
	 * 
	 * }else{ Log.e("", false+"change"); }
	 * 
	 * 
	 * lastChangeTime = time; return false;
	 * 
	 * }
	 */
	// 2015.6.23 v.c
	public void postO2LoveOrDeleteSongByOther(String url, String provider,
			String str, final ChannelHandlerContext ctx, final String action) {
		if (provider == "o2") {
			return;
		}
		
		// 向服务器post 从网易加载的歌单 ，并且在返回函数中添加喜欢属性 对用户以前删除歌曲进行处理
		final Map<String, String> param = new HashMap<String, String>();
		
		UrlDecode.parseParameters(param, url, null);
		param.put("provider", provider);
		param.put("mediaMetadatas", str);
		param.put("action", action);
		
		url = UrlDecode.getUrl(param, url, null);
		url = url.replace(" ", "");
		
		RequestQueue queue = RequestManager.getRequestQueue();
		Logger.d(TAG, "Responseurl==" + url);

		RequestManager.sendpost(activity, url, new CloudListener() {
			
			@Override
			public void onResponse(String response) {

				Logger.d(TAG, "postO2Songlist_onResponse==" + response);
				if (response == null) {
					Toast.makeText(PlayFragment.this.getContext(),
							"收藏失败", Toast.LENGTH_SHORT).show();
					mPopWindow.setFavorite(false);
					return;
				}

				if (response
						.equals("{\"message\":\"系统错误，操作失败\",\"status\":\"ERROR\"}")) {
					Logger.e(TAG, "收藏失败" + response);
					Toast.makeText(PlayFragment.this.getContext(),
							"收藏失败", Toast.LENGTH_SHORT).show();
					mPopWindow.setFavorite(false);
					PlayListManage.getInstance().getCurrentMedia()
							.setFavorite(false);
					return;

				}
				GetMetadataResponse<AbstractMedia> result = RequestManager
						.parseJsonResponse(response);

				MediaMetadata mediaMetadata = (MediaMetadata) result
						.getGetMetadataResult()
						.getMediaCollectionOrMediaMetadata().get(0);

				// mediaMetadata.
				// Logger.i(TAG,"mediaMetadata=="+mediaMetadata.getTitle()+mediaMetadata.getDynamic().getProperty());
				String isLikeResult = mediaMetadata.getDynamic()
						.getProperty().get(0).getValue();
				if (isLikeResult.equals(RESPONSE_VLAUE_IS_FAVORITE)) {

					Toast.makeText(PlayFragment.this.getContext(),
							"收藏成功", Toast.LENGTH_SHORT).show();
					mPopWindow.setFavorite(true);
					PlayListManage.getInstance().getCurrentMedia()
							.setFavorite(true);
					if (ctx == null) {
						FavoriteBean favoriteBbean = new FavoriteBean();
						favoriteBbean.setCurrentItemID(PlayListManage
								.getInstance().getCurrentMedia()
								.getItemID());
						favoriteBbean.setLike(true);
						favoriteBbean.setProvider(PlayListManage
								.getInstance().getCurrentMedia()
								.getServiceID());
						LinkManager.getInstance().favorite(
								favoriteBbean);
					}
					// MocoDownloadManager.getInstance().startDownload(info);
				} else {
					Toast.makeText(PlayFragment.this.getContext(),
							"收藏失败", Toast.LENGTH_SHORT).show();
					mPopWindow.setFavorite(false);
					PlayListManage.getInstance().getCurrentMedia()
							.setFavorite(false);
					// MocoDownloadManager.getInstance().removeDownload(info);
				}

				LanServer.responseResult(
						JsonMessageType.FAVORITE.toString(), 0, null,
						ctx);
			}

			
			@Override
			public void onError(int err, String msg) {
				Logger.e(
						TAG,
						"post_o2_songliston_ErrorResponse"
								+ msg);
				if (action.equals("favorite")) {
					Toast.makeText(PlayFragment.this.getContext(),
							"收藏失败", Toast.LENGTH_SHORT).show();
					mPopWindow.setFavorite(false);
				}
				LanServer.responseResult(
						JsonMessageType.FAVORITE.toString(), -1, null,
						ctx);

			}
		});

	}
}
